package com.lhn.bbs.controller;

import com.lhn.bbs.dto.ActionResult;
import com.lhn.bbs.entity.Class1;
import com.lhn.bbs.entity.Userclass;
import com.lhn.bbs.service.Class1Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RequestMapping("/class1")
@RestController
@Slf4j
public class Class1Controller {

    @Autowired
    private Class1Service class1Service ;

    /**
     * 添加班级
     * @param class1  添加班级需要的参数
     * @return 返回值类型为 ActionResult
     */
    @RequestMapping(value = "/addclass",method = RequestMethod.POST)
    public ActionResult addClass(@RequestBody Class1 class1){
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
//        System.out.println(formatter.format(date));
        String format = formatter.format(date);

        class1.setClasstime(format);
        log.info("++++++++"+class1);
        return class1Service.addClass(class1);
    }

    /**
     * 查询班级主题
     */
    @RequestMapping(value = "/getclasstheme",method = RequestMethod.GET)
    public ActionResult getClassTheme(@RequestParam(value = "userid") Integer userid,
                                      @RequestParam(value = "page") Integer page,
                                      @RequestParam(value = "limit") Integer limit){
        log.info("++++++++"+userid+"=="+page+"+++"+limit);
        return class1Service.findClassTheme(userid,page,limit);
    }
//    根据老师id查询班级
    @RequestMapping(value = "/findclassByteacherid",method = RequestMethod.GET)
    public ActionResult findclassByteacherid(@RequestParam(value = "userid") Integer userid){
        log.info("++++++++"+userid+"++++");
        return class1Service.findclassByteacherid(userid);
    }
//    根据班级id删除班级
    @RequestMapping(value = "/deleteclass", method = RequestMethod.GET)
    public ActionResult deleteClassById(@RequestParam(value = "classid") Integer classid){

//        log.info("+++++++++"+classid);
        return class1Service.deleteClassById(classid);
    }
//    退出班级
    @RequestMapping(value = "/studentdeleteclass", method = RequestMethod.GET)
    public ActionResult studentdeleteclass(@RequestParam(value = "classid") Integer classid,
                                           @RequestParam(value = "userid") Integer userid){

        log.info("+++++++++"+classid+"+++"+userid);
        return class1Service.studentdeleteclass(classid,userid);
    }
//   查询班级人员信息
    @RequestMapping(value = "/classstudents", method = RequestMethod.GET)
    public ActionResult findClassStudentS(@RequestParam(value = "classid") Integer classid,
                                          @RequestParam(value = "page") Integer page,
                                          @RequestParam(value = "limit") Integer limit){

        log.info("+++++++++"+classid+page+limit);
        return class1Service.findCLassStudent(classid,page,limit);
    }

    /**
     * 根据用户id将用户踢出班级
     * @param classid
     * @param page
     * @param limit
     * @return
     */
   @RequestMapping(value = "/deleteclassbyid", method = RequestMethod.GET)
    public ActionResult findClassStudentS(@RequestParam(value = "userid") Integer userid,
                                          @RequestParam(value = "classid") Integer classid){

        log.info("+++++++++"+userid+"+++"+classid);
        return class1Service.deleteClassByid(userid,classid);
    }

    /**
     * 模糊查询班级
     * @param userid
     * @param classid
     * @return
     */
   @RequestMapping(value = "/likeclass", method = RequestMethod.GET)
    public ActionResult findlikeclass(@RequestParam(value = "likeclassname") String likeclassname,
                                      @RequestParam(value = "page") Integer page,
                                      @RequestParam(value = "limit")Integer limit){

        log.info("+++++++++"+likeclassname+"+++"+page);
        return class1Service.findlikeclass(likeclassname,page,limit);
    }
//    加入班级
    @RequestMapping(value = "/joinclassByid", method = RequestMethod.POST)
    public ActionResult joinclassByid(@RequestBody Userclass userclass){

        log.info("+++++++++"+userclass.getClassid());
        return class1Service.joinclassByid(userclass);
    }
//   查询所有的班级
    @RequestMapping(value = "/allclass", method = RequestMethod.GET)
    public ActionResult findlikeclass(@RequestParam(value = "page") Integer page,
                                      @RequestParam(value = "limit")Integer limit){

        log.info("+++++++++"+limit+"+++"+page);
        return class1Service.findAllclass(page,limit);
    }

}
